{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.【判断】Python定义类的方式与C++、Java相同，均为“关键字class + { } + 缩进”格式。（ ）  \n",
    "\n",
    "A. √  \n",
    "B. ×"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：B。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.【判断】如下类的定义方式是否正确？（ ）\n",
    "```\n",
    "class Person:\n",
    "    nationality = 'China'     \n",
    "    def __init__(argument, name, age):\n",
    "        argument.name = name \n",
    "        age = age     \n",
    "    def say_hi(argument):\n",
    "        print(argument.name)```\n",
    "A. √  \n",
    "B. ×"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：A。  \n",
    "解析：self不是python关键字，在实例方法中换成argument等也可正常执行。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.【填空】以下代码错误的语句为：（ ）。\n",
    "```\n",
    "class func:\n",
    "    def instance_func(self):\n",
    "        print('实例方法',self)\n",
    "\n",
    "    @classmethod\n",
    "    def class_func(cls):\n",
    "        print('类方法',cls)\n",
    "        \n",
    "    @staticmethod\n",
    "    def static_func():\n",
    "        print('静态方法')\n",
    "        \n",
    "func.instance_func()\n",
    "func.class_func()\n",
    "func.static_func()\n",
    "\n",
    "m=func()\n",
    "m.instance_func()\n",
    "m.class_func()\n",
    "m.static_func()```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：func.instance_func()。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4.【填空】子类可以继承父类的public属性与（ ）属性，但不能继承父类的（ ）属性。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：protected；private。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "5.【填空】如下代码的输出结果为：（ ）。\n",
    "```\n",
    "class Student:\n",
    "    name=\"wang\"\n",
    "    __age=16\n",
    "        \n",
    "    def __init__(self,name,age):\n",
    "        self.name = name\n",
    "        self.age = age\n",
    "        print(self.name,self.age)\n",
    "        \n",
    "s1= Student(\"zhang\", 18)\n",
    "s2= Student(\"li\", 20)\n",
    "print(s2._Student__age)```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：\n",
    "```\n",
    "zhang 18\n",
    "li 20\n",
    "16```\n",
    "解析：双下划线前缀的属性和方法可以称为“伪私有”属性和方法。通过在带双下划线前缀的变量名前再加上“_类名”，从而可以在类外直接访问。"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
